package name.fuhan.swiperefreshvpagerindicator.view;

import name.fuhan.swiperefreshvpagerindicator.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class TiaoTiaoView extends View {

	private int height;
	private int width;
	private int count = 3;
	private float space = 10f;
	private Paint paint1 = new Paint();
	private float progress = 0.0f;
	private int bgColor = 0xffefefef;
	{
		paint1.setAntiAlias(true);
		paint1.setStyle(Paint.Style.FILL);
	}

	public void setCount(int count){
		this.count = count==0?1:count;
		paint1.setColor(getResources().getColor(R.color.c_title));
		postInvalidate();
	}
	public void setProgress(float progress) {
		this.progress = progress;
		postInvalidate();
	}

	public TiaoTiaoView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawColor(bgColor );
		float kuan = width*1.0f/count;
//		float r = (kuan < height?kuan:height)/2 - space/2;
//		float wz = 1.0f*width/count;
		canvas.drawRect(progress * kuan, 0, progress * kuan + kuan, height, paint1);
//		canvas.drawCircle(progress*wz+wz/2, 1.0f*height/2, r, paint2);
		if (progress>(count-1)) {
			canvas.drawRect((progress - count) * kuan, 0, (progress - count) * kuan + kuan, height, paint1);
//			canvas.drawCircle((progress - count) * wz + wz / 2, 1.0f * height / 2, r, paint2);
		}
		
	}
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		height = getMeasuredHeight();
		width = getMeasuredWidth();
	}

}
